package com.kaibes.platform.member;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.kaibes.module.user.UserService;
import com.kaibes.module.user.pojo.User;
import com.kaibes.orm.spring.TableInitialize;
import com.kaibes.platform.member.db.Member;
import com.kaibes.platform.member.db.MemberLevel;
import com.kaibes.platform.member.db.MemberLevelService;
import com.kaibes.platform.member.db.MemberService;

@Component
public class MemberLevelInitialize extends TableInitialize<MemberLevelService> {

    @Autowired
    private UserService userService;
    @Autowired
    private MemberService memberService;
    
    @Override
    public void onEmpty(MemberLevelService service) {
        final MemberLevel level = new MemberLevel();
        level.setName("初级会员");
        level.setDescribe("系统自动生成");
        level.setLevel((short) 1);
        level.setExperience(0);
        service.save(level);
        
        List<User> users = userService.list();
        users.forEach(user->{
            Member member = new Member();
            member.setUserId(user.getId());
            member.setExperience(0);
            memberService.save(member);
        });
    }

}
